package com.wfk.utils;
import java.util.HashMap;
import java.util.Map;

public class ResponseData {

	private final String message;
	private final int code;
	private Map<String, Object> data = new HashMap<String, Object>();

	public String getMessage() {
		return message;
	}

	public int getCode() {
		return code;
	}

	public Map<String, Object> getData() {
		return data;
	}

	public ResponseData putDataValue(String key, Object value) {
		data.put(key, value);
		return this;
	}

	private ResponseData(int code, String message) {
		this.code = code;
		this.message = message;
	}
	
	private ResponseData(int code,String message,Map<String,Object> data) {
		this.code = code ;
		this.message = message ;
		this.data = data ; 
	}
	
	public static ResponseData build(int code,String message,Map<String,Object> data) {
		return new ResponseData(code,message,data) ;
	}

	public static ResponseData ok() {
		return new ResponseData(200, "Ok");
	}
	public static ResponseData ok(String message) {
		return build(200,message,null);
	}
	/**
	 * 资源未找到 404
	 * @return
	 */
	public static ResponseData notFound() {
		return new ResponseData(404, "Not Found");
	}
	
	/**
	 * 找不到方法
	 * @return
	 */
	public static ResponseData notMethod() {
		return new ResponseData(405, "Not Method") ;
	}

	/**
	 * 语法错误 400
	 * @return
	 */
	public static ResponseData badRequest() {
		return new ResponseData(400, "Bad Request");
	}

	/**
	 * 禁止访问 403
	 * @return
	 */
	public static ResponseData forbidden() { 
		return new ResponseData(403, "Forbidden");
	}

	/**
	 * 未经授权的 401
	 * @return
	 */
	public static ResponseData unauthorized() {
		return new ResponseData(401, "unauthorized");
	}

	/**
	 * 服务器错误 500
	 * @return
	 */
	public static ResponseData serverInternalError() {
		return new ResponseData(500, "Server Internal Error");
	}
	
	/** 
	 * 用户错误 1001
	 * @return
	 */
	public static ResponseData customerError() {
		return new ResponseData(1001, "customer Error");
	}
	
	/**
	 * 基础错误 1002
	 * @param message错误提示
	 * @return
	 */
	public static ResponseData baseError(String message) {
		return new ResponseData(1002, message);
	}
	
	/**
	 * 业务错误 1003
	 * @param message错误提示
	 * @return
	 */
	public static ResponseData baseServiceError(String message) {
		return new ResponseData(1003, message);
	}
	
}
